1 /* 2 Copyright: Marcelo S. N. Mancini (Hipreme|MrcSnm), 2018 - 2021 3 License: [https://creativecommons.org/licenses/by/4.0/|CC BY-4.0 License]. 4 Authors: Marcelo S. N. Mancini 5 6 Copyright Marcelo S. N. Mancini 2018 - 2021. 7 Distributed under the CC BY-4.0 License. 8 (See accompanying file LICENSE.txt or copy at 9 https://creativecommons.org/licenses/by/4.0/ 10 */ 11 module hip.api; 12 13 14 /** 15 * For building the API some rules must be followed: 16 * 17 * 1: Public Interfaces, Structs and Abstract Classes must always be declared somewhere at hip.api; 18 * 2: Methods will most of the time return an interface when dealing it at scripting time, at release 19 * build, the can return the entire class. 20 * 3: The User API will contain classes named as the same as those defined at the HipremeEngine, so 21 * the user will actually use some aliass. 22 * 4: When building for release (version(DirectCall)), api should publicly import the actual 23 * class definition. 24 * 5: For maintaining consistency, this package may declare some public imports that should be delegated 25 * to the actual API when that API is an aliased import. 26 */ 27 28 public import hip.api.impl; 29 public import hip.api.config; 30 31 32 enum HipAssetLoadStrategy 33 { 34 loadAll 35 } 36 37 version(ScriptAPI) version = UseExternalScene; 38 39 ///Most important functions here 40 version(UseExternalScene) 41 { 42 alias hipDestroyFn = extern(System) void function(Object); 43 __gshared hipDestroyFn hipDestroy; 44 } 45 46 version(DesktopRelease) 47 { 48 import app; 49 __gshared auto _keepMain = &main; ///TODO: Find some other way to make main to being stripped. 50 } 51 52 53 54 mixin template HipEngineMain(alias StartScene, HipAssetLoadStrategy strategy = HipAssetLoadStrategy.loadAll) 55 { 56 immutable string ScriptModules = import("scriptmodules.txt"); 57 pragma(msg, ScriptModules); 58 version(UseExternalScene) 59 { 60 __gshared AScene _exportedScene; 61 version(Windows) 62 { 63 import core.sys.windows.dll; 64 mixin SimpleDllMain; 65 } 66 export extern(System) AScene HipremeEngineGameInit() 67 { 68 import hip.api; 69 import hip.api.systems.system_binding; 70 import hip.api.input.binding; 71 import hip.api.filesystem.fs_binding; 72 import hip.api.game.game_binding; 73 import core.runtime; 74 import hip.api.internal:initializeHip; 75 import hip.api.renderer.core; 76 import hip.api.internal; 77 78 rt_init(); 79 initializeHip(); 80 initConsole(); 81 initFS(); 82 initG2D(); 83 // HipAudio.initAudio(); 84 alias renderFn = extern(System) IHipRenderer function(); 85 setHipRenderer((cast(renderFn)_loadSymbol(_dll, "HipRendererAPI"))()); 86 initInput(); 87 HipDefaultAssets.initGlobalAssets(); 88 HipAssetManager.initAssetManager(); 89 initTimerAPI(); 90 initGameAPI(); 91 initNet(); 92 93 mixin LoadAllAssets!(ScriptModules); 94 loadReferenced(); 95 96 return _exportedScene = new StartScene(); 97 } 98 export extern(System) void HipremeEngineGameDestroy() 99 { 100 if(_exportedScene) 101 { 102 _exportedScene.dispose(); 103 destroy(_exportedScene); 104 } 105 _exportedScene=null; 106 } 107 } 108 else 109 { 110 pragma(mangle, "HipremeEngineMainScene") 111 export extern(C) AScene HipremeEngineMainScene() 112 { 113 mixin LoadAllAssets!(ScriptModules); 114 loadReferenced(); 115 return new StartScene(); 116 } 117 } 118 }